package cn.com.pkas.xml
{
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.controls.Alert;
	
//	[Bindable]
	public class HM
	{
		private static var rsObj:Object = new Object();
		
		private var temp:String = null;
		
		private static var lang:String = "zh_HK";

		public function HM()
		{   
//			Alert.show("inti HM");
			
			if(isInit && rsObj != null){
				return ;
			}
			
//			rsObj = new Object();
				
			var zhHKObj:Object = new Object();
			var enUSObj:Object = new Object();
			
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE,function(e:Event):void{
//				Alert.show("a");
//				XML(e.target.data)

				var xml:XML = XML(e.target.data);
				
				var tempKey:String = null;
				var tempzhHK:String = null;
				var tempenUS:String = null;
				for(var i:int = 0 ; i < xml.children().length() ; i++){
//					Alert.show("中文"+xml.resource[i].resourceValue[0]);
					tempKey = xml.resource[i].@id;
					
					tempzhHK = xml.resource[i].resourceValue[0];
					tempenUS = xml.resource[i].resourceValue[1];
					
					zhHKObj[tempKey] = tempzhHK;
					enUSObj[tempKey] = tempenUS;
					
//					Alert.show("key: "+tempKey + "；中文："+tempzhHK+";英文: " +tempenUS);
				}
				rsObj["zh_HK"] = zhHKObj;
				rsObj["en_US"] = enUSObj;
//				Alert.show(rsObj["en_US"]['密码']);
//				Alert.show("123");
//				Alert.show(tempMap.getValue("密码") as String);
		
				xml = null;
				zhHKObj = null;
				enUSObj = null;
			});
			
//			Alert.show("456");
			loader.load(new URLRequest(ExternalInterface.call("function getUrl(){return document.location.href;}") + "view/common/resource.xml"));


		}
		
		public static function getValue(key:String):String{
		
			
//			if(key==0){
//				return '是';
//			}else {
//				return '否';			
//			}
//			temp = rsObj["en_US"][key];
//			Alert.show(key);
			if(rsObj[lang][key] == "" || rsObj[lang][key] == null){
				return key;
			}

			return rsObj[lang][key];
		}
	}
}